<!--
/*
#################################################################################
#
# Copyright (c) 2006 Michigan State University
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#################################################################################

#################################################################################
#
#	Author:
#		Nathan Collins <npcollins@gmail.com>
#
#################################################################################
*/

function focus_search() {
	document.searcher.s.focus();
}

function focus_search_adv() {
	document.creator.keywords.focus();
}

function validate() {
	// grab the search box
	var search = document.searcher.s.value;
	// trim the whitespace
	search = search.replace(/^\s+|\s+$/g,'');
	// check the length
	if (search.length > 1) {
		return true;
	}
	alert( "Your search was empty or too short. Please lengthen it and try again." );
	return false;
}

function validate2() {
	// grab the search box
	var search = document.searcher.s.value;
	// copy over within search if checked
	if (document.holder.narrow.checked == true) {
		document.searcher.w.value = document.holder.hold.value;
	}

	// trim the whitespace
	search = search.replace(/^\s+|\s+$/g,'');
	// check the length
	if (search.length > 1) {
		return true;
	}
	alert( "Your search was empty or too short. Please lengthen it and try again." );
	return false;
}

function home() {
	window.location = "index.py";
}

var searchShown = 0;

function toggleSearch() {
	cbox = document.getElementById('subform1');
	sbox = document.getElementById('subform2');
	if (searchShown == 0) {
		searchShown = 1;
		cbox.innerHTML = "<span class=\"smallish details\"><a onClick=\"toggleSearch();\">Hide Search</a></span><br>";
		sbox.style.display = 'block';
		focus_search();
	}
	else {
		searchShown = 0;
		cbox.innerHTML = "<span class=\"smallish details\"><a onClick=\"toggleSearch();\">Show Search</a></span><br>";
		sbox.style.display = 'none';
	}
}

function get_radio_value(arr) {
	max = arr.length;
	for (i = 0; i < max; i++) {
		if (arr[i].checked == true) {
			return arr[i].value;
		}
	}
	return '1';
}

function suggestValidate() {
	title = document.suggest.title.value;
	desc = document.suggest.description.value;
	if (title.length < 1) {
		alert('You must at least enter a title for your entry.');
		return false;
	}
	type = get_radio_value(document.suggest.type);
	if (type == '1') {
		/* modify checking */
		/* TODO */
	}
	else if (type == 'record') {
		if (title.length > 120) {
			alert('The title field is too long. For purposes of keeping the directory looking clean, the title should be no longer than 120 characters for records.');
			return false;
		}
		if (desc.length > 300) {
			alert('The description field is too long. For purposes of keeping the directory looking clean, the description should be no longer than 300 characters for records.');
			return false;
		}
	}
	else {
		if (title.length > 80) {
			alert('The title field is too long. For purposes of keeping the directory looking clean, the title should be no longer than 80 characters for directories and links.');
			return false;
		}
		if (desc.length > 120) {
			alert('The description field is too long. For purposes of keeping the directory looking clean, the description should be no longer than 120 characters for directories and links.');
			return false;
		}
	}
	return true;
}

//-->
